<?php
// 本类由系统自动生成，仅供测试用途
class ModelAction extends BaseAction {
    public function __construct() {
        parent::__construct();
        //权限判定
        
        //语言包设置
        $language['ch']=array(
            //头部
            "titlebt"=>'设计模式',
            "now_path"=>'当前位置',
            "header_admin"=>"设计模式",
            "header_add"=>"添加模块",
            "header_value1"=>"在这里，你可以设置",
            "header_value2"=>"模块",
            "header_value3"=>"其他3",
            "header_value4"=>"其他4",
            "header_value5"=>"其他5",
            "header_value6"=>"其他6",
            "titlebt2"=>"设计模式",
        );
        
        //解析语言包
        $this->assign("language",$language['ch']);
        
        
    }
    public function index(){
        $model=D("model");
        $name['title']=$model
                    ->where(array("model_parent_id"=>0))
                    ->order("model_order")
                    ->select();
        $name['model']=$model
                     ->where(array("model_parent_id"=>array("gt",0)))
                     ->order("model_order")
                     ->select();
        $this->assign("models",$name);
        $this->display();
    }
    
    public function insert(){
        $model=D("model");
        $name['title']=$model
                    ->where(array("model_parent_id"=>0))
                    ->order("model_order")
                    ->select();
        if(isset($_GET['sid'])&&  intval($_GET['sid'])>0){
            $this->assign("sid",intval($_GET['sid']));
        }
        $this->assign("models",$name);
        $this->display();
    }
    
    public function update(){
        if(isset($_GET['sid'])&&  intval($_GET['sid'])>0){
            $sid=intval($_GET['sid']);
            $model=D("model");
            $name['title']=$model
                    ->where(array("model_parent_id"=>0))
                    ->order("model_order")
                    ->select();
            //echo $model->getLastSql();
            $model_this=$model
                        ->where(array("model_id"=>$sid))
                        ->find();
            //echo $sid;
            //echo $model->getLastSql();
                $this->assign("models",$name);
                $this->assign("model_this",$model_this);
            $this->display();
        }else{
            $this->error("数据错误");
        }
        
    }
    
    public function del(){
        if(isset($_GET['sid'])&&  intval($_GET['sid'])>0){
            $sid=intval($_GET['sid']);
            $model=D("model");
            $del=$model
                ->where(array("model_id"=>$sid))
                ->delete();
            if($del){
                $this->success("删除成功");
                
            }else{
                $this->error("删除失败");
            }
        }else{
            $this->error("数据错误");
        }
    }
    
}